<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>06_计算器练习</title>
    </head>
    <body>
        <input type="text" id="i1"><br>
        <input type="text" id="i2"><br>
        <button onclick="calc('+')">加</button>
        <button onclick="calc('-')">减</button>
        <button onclick="calc('*')">乘</button>
        <button onclick="calc('/')">除</button>
        <br>
        <br>
        <h3>运算结果：<span></span></h3>

        <script>
            function calc(o){
                let n1 = document.querySelector('#i1').value;
                let n2 = document.getElementById('i2').value;
                n1=parseFloat(n1);
                n2=parseFloat(n2);
                let spanE = document.querySelector('span');
                switch (o) {
                    case '+':
                        spanE.innerHTML = n1+n2;
                        break;
                    case '-':
                        spanE.innerHTML = n1-n2;
                        break;
                    case '*':
                        spanE.innerHTML = n1*n2;
                        break;
                    case '/':
                        spanE.innerHTML = n1/n2;
                        break;


                }

            }

        </script>




    </body>
</html>